/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.playground.core.service;

import com.playground.core.entity.LoggedPlayer;

/**
 *
 * @author Tiago Peres
 */
// TODO:
public interface LoginService {
    
    /**
     * Register the player with the given player id as a logged user.
     * 
     * @param playerId the id of the player to log in
     * @return the loggedPlayer, null if the login was not successfull
     */
    LoggedPlayer login(long playerId);
    
    /**
     * Register the player with the given facebook id as a logged user.
     * 
     * @param facebookId the facebook id of the player to log in
     */
    void login(String facebookId);
    
    /**
     * Verifies if the given playerId corresponds to a logged player, if the
     * logged player's key corresponds to the key passed as parameter, and if
     * the login is still valid.
     * The login is still valid if the player's last action was done "timeout"
     * milleseconds before now, where "timeout" is predefined value.
     * If it is detected that the login is expired (not valid), the LoggedPlayer
     * is deleted.
     * In case the loggedPlayer exists, its key is the same as the key passed as
     * parameter and it's still valid, the loggedPlayer is returned. Otherwise,
     * null is returned.
     * 
     * @param playerId the id of the logged player
     * @param key the key to be verified
     * @return the logged user if all verifications pass
     */
    LoggedPlayer verifyLoggedPlayerKey(long playerId, String key);
    
    /**
     * Log out the specified player, it it exists.
     * 
     * @param loggedPlayer the player to be logged out.
     */
    void logout(LoggedPlayer loggedPlayer);
}
